﻿using RpcModel;
using RpcSync.Collect;
using RpcSync.Collect.Model;
using RpcSync.Service.ConfigService;
using RpcSync.Service.Interface;

namespace RpcSync.Service.Event
{
    /// <summary>
    /// 系统配置服务
    /// </summary>
    internal class RpcSysConfigEvent : RpcClient.Interface.IRpcApiService
    {
        private ISysConfigCollect _SysConfig;
        private IConfigRefreshService _Refresh;
        public RpcSysConfigEvent(ISysConfigCollect sysConfig, IConfigRefreshService refresh)
        {
            this._Refresh = refresh;
            this._SysConfig = sysConfig;
        }
        /// <summary>
        /// 刷新系统配置
        /// </summary>
        public void RefreshSysConfig()
        {
            this._Refresh.Refresh();
        }

        /// <summary>
        /// 获取系统配置
        /// </summary>
        /// <param name="source">事件原</param>
        /// <returns></returns>
        public  RemoteSysConfig GetSysConfig(MsgSource source)
        {
            SysConfigItem item = this._SysConfig.GetSysConfig(source.SystemType);
            return new RemoteSysConfig
            {
                ConfigMd5 = item.Md5,
                ConfigData = item.Filters(source)
            };

        }
    }
}
